package org.teachertools.web.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.teachertools.data.Matiere;
import org.teachertools.services.MatiereService;
import org.teachertools.web.forms.MatiereForm;
import org.teachertools.web.forms.MatiereFormMapping;

public class MatiereViewAction extends CommonAction {
    @Override
    protected ActionForward process(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        MatiereService matiereService = this.getServiceLocator().getMatiereService();
        Long id = Long.parseLong(request.getParameter("id"));
        Matiere matiere = matiereService.get(id);
        MatiereForm matiereForm = (MatiereForm) form;
        MatiereFormMapping.mappingDTOToForm(matiere, matiereForm);
        matiereForm.setIsUpdate(true);
        addCategoryList(request);
        return (mapping.findForward(CONTINUE));
    }
}
